/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


var fieldLabel = new Array('供电局','部门、分局或县公司名称','测点名称','电压类别','测点城农网','测点电压等级','电压上限定值','电压下限定值','测点所属供电所名称' ,'测点地域',
                            '测点位置标识','测点所属变电站名称','测点所属变电站电压等级','用户名称','公变名称','状态','测点生效日期','测点安装位置','装置类别', '生产厂家',
                            '装置型号','通信方式','通信卡号','装置IP','装置安装日期','上次校验日期','监测点编码','装置编码','终端地址','行政区域吗' ,
                            '组编码' ,'唯一码' ,'通道' ,'启用/停用','停用日期','停用原因','有效期','装置端口','出厂日期');//,'有效期',
                           //'出厂日期','端口','唯一码','监测点ID','组编码','行政区域吗','通道','在线情况','管理人员','备注'
var fieldName=new Array("company","subCompany","name","pointType","pointType2","voltageLevelName","upperLimit","lowerLimit","shortName","pointArea",
                        "pointPosition",'stationName',"stationVoltageLevel","userName","publicName","status","effectTime","installSite","deviceType","manufactoryName",
                        "model","commTypeName","mobileNo","ip","installTime","checkTime","code","deviceNo","terminalNo","adminAreaCode",
                        "zbm","uniqueCode","channel","status","stopTime","stopReason","expireTime","port","produceTime","rn","id","reportStatusCh","startStatusCh");//,"yxq",
                        //"ccrq","port","wym","id","zbm","xzqym","td","zxqk","glry","bz"
var _pageSize=20;

var now  = new Date();
var store=new Ext.data.JsonStore({               
    
    url: basePath+"servlet/system/PointLoad",    
    root: 'data',
    idProperty: 'id',
    totalProperty: 'count',
    fields: fieldName,
    autoLoad: true,
    baseParams: {start: 0, limit: _pageSize,cmd:cmd,loadCmd:loadCmd,reportStatus:reportStatus,dateTo:now.format('Ym')}
});

var centercolumnModel = new Ext.grid.ColumnModel({
    columns: [    
    {header: '序号',width: 40, dataIndex: 'rn', align: 'center'},    
    {header: fieldLabel[0],width: 100, dataIndex: fieldName[0], align: 'center'},
        {header: fieldLabel[1],width: 100, dataIndex: fieldName[1], align: 'center'},
        {header: fieldLabel[2],width: 100, dataIndex: fieldName[2], align: 'center'},
        {header: fieldLabel[3],width: 100, dataIndex: fieldName[3], align: 'center'},
        {header: fieldLabel[4],width: 100, dataIndex: fieldName[4], align: 'center'},
        {header: fieldLabel[5],width: 100, dataIndex: fieldName[5], align: 'center'},
        {header: fieldLabel[6],width: 100, dataIndex: fieldName[6], align: 'center'},
        {header: fieldLabel[7],width: 100, dataIndex: fieldName[7], align: 'center'},
        {header: fieldLabel[8],width: 100, dataIndex: fieldName[8], align: 'center'},
        {header: fieldLabel[9],width: 100, dataIndex: fieldName[9], align: 'center'},
        
        {header: fieldLabel[10],width: 100, dataIndex: fieldName[10], align: 'center'},
        {header: fieldLabel[11],width: 100, dataIndex: fieldName[11], align: 'center'},
        {header: fieldLabel[12],width: 100, dataIndex: fieldName[12], align: 'center'},
        {header: fieldLabel[13],width: 100, dataIndex: fieldName[13], align: 'center'},
        {header: fieldLabel[14],width: 100, dataIndex: fieldName[14], align: 'center'},
        {header: fieldLabel[15],width: 100, dataIndex: "reportStatusCh", align: 'center'},
        {header: fieldLabel[16],width: 100, dataIndex: fieldName[16], align: 'center', xtype: 'datecolumn', format: 'Y-m-d'},
        {header: fieldLabel[17],width: 100, dataIndex: fieldName[17], align: 'center'},
        {header: fieldLabel[18],width: 100, dataIndex: fieldName[18], align: 'center'},
        {header: fieldLabel[19],width: 100, dataIndex: fieldName[19], align: 'center'},
        
        {header: fieldLabel[20],width: 100, dataIndex: fieldName[20], align: 'center'},
        {header: fieldLabel[21],width: 100, dataIndex: fieldName[21], align: 'center'},
        {header: fieldLabel[22],width: 100, dataIndex: fieldName[22], align: 'center'},
        {header: fieldLabel[23],width: 100, dataIndex: fieldName[23], align: 'center'},
        {header: fieldLabel[24],width: 100, dataIndex: fieldName[24], align: 'center', xtype: 'datecolumn', format: 'Y-m-d'},
        {header: fieldLabel[25],width: 100, dataIndex: fieldName[25], align: 'center', xtype: 'datecolumn', format: 'Y-m-d'},
        {header: fieldLabel[26],width: 100, dataIndex: fieldName[26], align: 'center'},
        {header: fieldLabel[27],width: 100, dataIndex: fieldName[27], align: 'center'},
        {header: fieldLabel[28],width: 100, dataIndex: fieldName[28], align: 'center'},
        {header: fieldLabel[29],width: 100, dataIndex: fieldName[29], align: 'center'},
        
        {header: fieldLabel[30],width: 100, dataIndex: fieldName[30], align: 'center'},
        {header: fieldLabel[31],width: 100, dataIndex: fieldName[31], align: 'center'},
        {header: fieldLabel[32],width: 100, dataIndex: fieldName[32], align: 'center'},
        {header: fieldLabel[33],width: 100, dataIndex: "startStatusCh", align: 'center'},
        {header: fieldLabel[34],width: 100, dataIndex: fieldName[34], align: 'center', xtype: 'datecolumn', format: 'Y-m-d'},
        {header: fieldLabel[35],width: 100, dataIndex: fieldName[35], align: 'center'},
        {header: fieldLabel[36],width: 100, dataIndex: fieldName[36], align: 'center', xtype: 'datecolumn', format: 'Y-m-d'},
        {header: fieldLabel[37],width: 100, dataIndex: fieldName[37], align: 'center'},
        {header: fieldLabel[38],width: 100, dataIndex: fieldName[38], align: 'center', xtype: 'datecolumn', format: 'Y-m-d'}
    ],
    defaultSortable: true
});
var dateTo = {
    xtype: 'datefield',
    id: 'DateTo',
    format: 'Y年m月',
    width: 150,
    value:now,
    listeners: {
        select: function(c, date) {            
            store.baseParams.dateTo = date.format('Ym');
        }
    }  
};
//alert(reportStatus);
//alert(Ext.getCmp('ReportStatus'));
Ext.getCmp('ReportStatus').setValue(reportStatus);
var centergrid=new Ext.grid.GridPanel({
    title: currentOrgName+' 监测点台帐汇总表',
    store: store,
    colModel:centercolumnModel,
    enableColumnMove: false,
    viewConfig: {
        forceFit: false
    },
    
    loadMask: true,
    tbar: new Ext.Toolbar([
        reportCombo,
        rangeCombo,        
        pointTypeCombo,
        pointType2Combo,
        pointText,'-',
        dateTo,
    searchButton,
    '-',
    {
        xtype: 'button',
        text: '导出',
        iconCls: 'icon-excel',
        width: 60,
        style: {
            marginLeft: '20px'
        },
        handler: downloadExcel
    }
    ]),
    bbar: new Ext.PagingToolbar({
        pageSize: _pageSize,
        store: store,
        displayInfo: true,
        displayMsg: '显示记录：{0} - {1}   总记录：{2}',
        emptyMsg:  '目前没有信息'
    })
});

function downloadExcel(){    
    store.baseParams.type=22;
    var encodeParams = Ext.urlEncode(store.baseParams);
    open(basePath+'servlet/common/ExcelFileCreate?'+encodeParams);
}

function buildWindow(){
    var applicationUI = new Ext.Viewport({
        layout:'fit',
        items: [
            centergrid
        ]
    });
    if(reportStatus ===1){
        //Ext.getCmp('ReportStatus').setVisible(false);
        Ext.getCmp('ReportStatus').setValue(1);
    }
    if(cmd ==="general"){
        Ext.getCmp('DateTo').setVisible(false);
        
    }
}
Ext.onReady(buildWindow); 
